package com.wz.producerserv.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.wz.producerserv.service.ProducerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/producer")
@RefreshScope
public class ProducerController {

    @Value("${defaultValue:Hello}")
    private String setPrefix;

    @Autowired
    private ProducerService producerService;

    @GetMapping("/addPrefix")
    @SentinelResource(value = "addPrefix", blockHandler = "addPrefixBlock")
    public String addPrefix(@RequestParam("name") String name) {
        return producerService.addPrefix(name, setPrefix);
    }

    public String addPrefixBlock(String name, BlockException blockException) {
        log.info("addPrefix接口被限流");
        return name;
    }

}
